*----------------------------------------------------------------------*
***INCLUDE LYBC_SWS_TBMT_CNDF01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form SET_FIELD_DROPDOWNLIST
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM SET_FIELD_DROPDOWNLIST .
  TYPE-POOLS : VRM.
  DATA: LV_FIELD   TYPE VRM_ID,
        LS_LISTBOX LIKE LINE OF GT_LISTBOX.

  DATA:
    LT_SPLIT_FIELD TYPE STANDARD TABLE OF CHAR50,
    LT_TEMPL_H     TYPE STANDARD TABLE OF YBC_SWS_TEMPL_H WITH HEADER LINE.

  REFRESH GT_LISTBOX.

  SELECT *
    INTO TABLE LT_TEMPL_H
    FROM YBC_SWS_TEMPL_H
   WHERE TEMPLATE = YBC_SWS_TEMPL_H-TEMPLATE
     AND LANGUAGE = YBC_SWS_TEMPL_H-LANGUAGE.
*  IF SY-SUBRC = 0.
*    MESSAGE S022(YBC_SWS).
*  ENDIF.

  LOOP AT LT_TEMPL_H.
    IF LT_TEMPL_H-FIELD_NAME CS '&'.
      REFRESH LT_SPLIT_FIELD[].
      SPLIT LT_TEMPL_H-FIELD_NAME AT '&' INTO TABLE LT_SPLIT_FIELD.
      LOOP AT LT_SPLIT_FIELD INTO DATA(LV_SFIELD).
        CONDENSE LV_SFIELD.
        LS_LISTBOX-KEY = LV_SFIELD.
        LS_LISTBOX-TEXT = LT_TEMPL_H-FIELD_DESC.
        APPEND LS_LISTBOX TO GT_LISTBOX.
      ENDLOOP.

    ELSE.
      LS_LISTBOX-KEY = LT_TEMPL_H-FIELD_NAME.
      LS_LISTBOX-TEXT = LT_TEMPL_H-FIELD_DESC.
      APPEND LS_LISTBOX TO GT_LISTBOX.
    ENDIF.
  ENDLOOP.

  LOOP AT TCTRL_YBC_SWS_WF_CND-COLS INTO DATA(LS_COL).
    IF LS_COL-SCREEN-NAME = 'YBC_SWS_WF_CND-FIELD'.
* 下拉列表赋值
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          ID     = 'YBC_SWS_WF_CND-FIELD'
          VALUES = GT_LISTBOX.
    ENDIF.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form form_f4_cnds
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FORM_F4_CNDS .
  DATA: LS_FIELD      TYPE RSDSFIELDS,
        LV_FIELD      TYPE TEXT40,
        LT_FIELD      TYPE STANDARD TABLE OF RSDSFIELDS,
        LT_FIELD_DESC TYPE STANDARD TABLE OF FLDCONVERT,
        LT_FIELD_TEXT TYPE TABLE OF RSDSTEXTS WITH HEADER LINE,
        L_SELID       TYPE DYNSELID,
        L_REPID       TYPE SY-REPID,
        LS_PFKEY      TYPE RSDSPFKEY,
        LS_RANGE      TYPE RSDS_RANGE,
        LS_FRANGE     TYPE RSDS_FRANGE,
        LT_FRANGE     TYPE RSDS_FRANGE_T,
        LT_RANGE      TYPE RSDS_TRANGE,
        LV_JSON       TYPE STRING.

  DATA:
    IT_DYNPFIELDS TYPE STANDARD TABLE OF DYNPREAD,
    WA_DYNPFIELDS TYPE DYNPREAD,
    W_STEPL       LIKE SY-STEPL.

  "BREAK-POINT 'SAP816'.
  CLEAR IT_DYNPFIELDS.

  CALL FUNCTION 'DYNP_GET_STEPL'
    IMPORTING
      POVSTEPL        = W_STEPL
    EXCEPTIONS
      STEPL_NOT_FOUND = 1
      OTHERS          = 2.

  IF W_STEPL IS INITIAL.
    GET CURSOR LINE W_STEPL.
  ENDIF.

  CLEAR WA_DYNPFIELDS.
  WA_DYNPFIELDS-STEPL = W_STEPL.
  WA_DYNPFIELDS-FIELDNAME  = 'YBC_SWS_WF_CND-FIELD'.
  APPEND WA_DYNPFIELDS TO IT_DYNPFIELDS.

  CLEAR WA_DYNPFIELDS.
  WA_DYNPFIELDS-STEPL = W_STEPL.
  WA_DYNPFIELDS-FIELDNAME  = 'YBC_SWS_WF_CND-CNDS'.
  APPEND WA_DYNPFIELDS TO IT_DYNPFIELDS.


  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      DYNAME     = SY-REPID
      DYNUMB     = SY-DYNNR
    TABLES
      DYNPFIELDS = IT_DYNPFIELDS.
  IF SY-SUBRC <> 0.
    RETURN.
  ENDIF.

  CLEAR WA_DYNPFIELDS.
  READ TABLE IT_DYNPFIELDS WITH KEY FIELDNAME  = 'YBC_SWS_WF_CND-FIELD' INTO WA_DYNPFIELDS.
  IF WA_DYNPFIELDS-FIELDVALUE IS INITIAL.
    RETURN.
  ENDIF.

  CONDENSE WA_DYNPFIELDS-FIELDVALUE.
  LV_FIELD = WA_DYNPFIELDS-FIELDVALUE.
  LS_FIELD-FIELDNAME = WA_DYNPFIELDS-FIELDVALUE.
  LS_FIELD-TYPE = 'C'.
  LS_FIELD-WHERE_LENG = 30.
  APPEND LS_FIELD TO LT_FIELD.

  CLEAR LT_FIELD_TEXT.
  LT_FIELD_TEXT-FIELDNAME = WA_DYNPFIELDS-FIELDVALUE.
  LT_FIELD_TEXT-TEXT = WA_DYNPFIELDS-FIELDVALUE.
  APPEND LT_FIELD_TEXT.

  CLEAR WA_DYNPFIELDS.
  READ TABLE IT_DYNPFIELDS WITH KEY FIELDNAME  = 'YBC_SWS_WF_CND-CNDS' INTO WA_DYNPFIELDS.
  IF WA_DYNPFIELDS-FIELDVALUE IS NOT INITIAL.
    CLEAR: LS_FRANGE, LS_RANGE.
    LS_FRANGE-FIELDNAME = LV_FIELD.
    LV_JSON = WA_DYNPFIELDS-FIELDVALUE.
    /UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON =  LV_JSON
                CHANGING DATA = LS_FRANGE-SELOPT_T ).
    APPEND LS_FRANGE TO LT_FRANGE.
    LS_RANGE-TABLENAME = 'RSDS_DUMMY'.
    LS_RANGE-FRANGE_T = LT_FRANGE[].
    APPEND LS_RANGE TO LT_RANGE.
  ENDIF.

  CALL FUNCTION 'FREE_SELECTIONS_INIT'
    EXPORTING
      KIND             = 'F'
      FIELD_RANGES_INT = LT_RANGE[]
    IMPORTING
      SELECTION_ID     = L_SELID
    TABLES
      FIELDS_TAB       = LT_FIELD[]
      FIELD_TEXTS      = LT_FIELD_TEXT[].

  LS_PFKEY-PROGRAM = SY-REPID.

  CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
    EXPORTING
      SELECTION_ID    = L_SELID
      TITLE           = 'Please input'
      AS_WINDOW       = 'X'
      PFKEY           = LS_PFKEY
      TREE_VISIBLE    = ''
    IMPORTING
      FIELD_RANGES    = LT_RANGE
    TABLES
      FIELDS_TAB      = LT_FIELD[]
    EXCEPTIONS
      INTERNAL_ERROR  = 1
      NO_ACTION       = 2
      SELID_NOT_FOUND = 3
      ILLEGAL_STATUS  = 4
      OTHERS          = 5.

  LOOP AT LT_RANGE INTO LS_RANGE.
    LOOP AT LS_RANGE-FRANGE_T INTO LS_FRANGE.
      LV_JSON = /UI2/CL_JSON=>SERIALIZE( DATA = LS_FRANGE-SELOPT_T ).
      EXIT.
    ENDLOOP.
    EXIT.
  ENDLOOP.

  "LV_JSON =  /UI2/CL_JSON=>SERIALIZE( DATA = LT_RANGE[] ).

  REFRESH IT_DYNPFIELDS[].
  CLEAR WA_DYNPFIELDS.
  WA_DYNPFIELDS-STEPL = W_STEPL.
  WA_DYNPFIELDS-FIELDNAME  = 'YBC_SWS_WF_CND-CNDS'.
  WA_DYNPFIELDS-FIELDVALUE = LV_JSON.
  APPEND WA_DYNPFIELDS TO IT_DYNPFIELDS.

  CALL FUNCTION 'DYNP_VALUES_UPDATE'
    EXPORTING
      DYNAME               = SY-REPID
      DYNUMB               = SY-DYNNR
    TABLES
      DYNPFIELDS           = IT_DYNPFIELDS
    EXCEPTIONS
      INVALID_ABAPWORKAREA = 1
      INVALID_DYNPROFIELD  = 2
      INVALID_DYNPRONAME   = 3
      INVALID_DYNPRONUMMER = 4
      INVALID_REQUEST      = 5
      NO_FIELDDESCRIPTION  = 6
      UNDEFIND_ERROR       = 7
      OTHERS               = 8.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_ZHANGE_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FORM_ZCHANGE_DATA .
  IF YBC_SWS_WF_CND-FIELD IS INITIAL.
    MESSAGE E023(YBC_SWS).
  ENDIF.

  READ TABLE GT_LISTBOX INTO DATA(LS_LISTBOX) WITH KEY KEY = YBC_SWS_WF_CND-FIELD.
  IF SY-SUBRC = 0.
    YBC_SWS_WF_CND-NAME = LS_LISTBOX-TEXT.
  ENDIF.
ENDFORM.
